package com.hello.ATM;

import java.util.Scanner;

public class Function {
    Scanner in = new Scanner(System.in);
    double yue;
    Function(double d){
        yue=d;
    }

    void print(){
        System.out.println("请选择功能");
        System.out.println("1查询余额");
        System.out.println("2存钱");
        System.out.println("3取钱");
        System.out.println("4退出");
            select();
            //print();


    }

    void select(){
        loop:while (true){
            int input = in.nextInt();
            switch (input) {
                case 1:
                    System.out.println(yue);
                    print();
                    break;
                case 2:
                    System.out.println("请输入要存的金额");
                    double cun = in.nextDouble();
                    if (cun > 0) {
                        yue += cun;
                        System.out.println("当前余额为" + (yue));
                        print();
                        break;
                    } else {
                        System.out.println("请输入符合要求的金额");
                        break;
                    }
                case 3:
                    System.out.println("请输入要取的金额");
                    double qu = in.nextDouble();
                    if (qu <= yue && qu > 0) {
                        yue -= qu;
                        System.out.println("当前余额为" + (yue));
                        print();
                        break;
                    } else {
                        System.out.println("请输入符合要求的金额");
                        break;
                    }
                case 4:
                    System.out.println("退出成功，欢迎下次登录");
                    //Login login=new Login(123456);
                    //login.pasd();
                  break loop;
                   // System.exit(-1);

                default:
                    System.out.println("请重新选择");
                    break;
            }
            return;
            }

        }
}

